home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 1 / Meeting Pearls Vol 1 (1994).iso / installed_progs / hard / galer / source / src.lha / Source / GALer / GAL.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-13  |  25.0 KB  |  1,197 lines

  1. /****************************************************************/
  2. /*                                */
  3. /* GAL.c - routines for reading and programming GALs        */
  4. /*                                */
  5. /*                                 */
  6. /****************************************************************/
  7.  
  8.  
  9.  
  10. #include <exec/types.h>
  11. #include <intuition/intuition.h>
  12. #include <ctype.h>
  13. #include <stdio.h>
  14. #include <string.h>
  15.  
  16. #include <libraries/reqtools.h>
  17. #include <proto/locale.h>
  18. #include <proto/reqtools.h>
  19.  
  20. #include "GALer.h"
  21. #include "Localize.h"
  22.  
  23.  
  24.  
  25. extern    struct AppString { LONG   as_ID;
  26.                 STRPTR as_Str;
  27.              };
  28.  
  29. extern    struct AppString AppStrings[];
  30.  
  31. extern    char    path[];
  32. extern    int    GALType, JedecSecurity, JedecGALType;
  33. extern    struct    JedecStruct    Jedec;
  34. extern    struct    Configuration    Config;
  35. extern    struct    Catalog        *catalog;
  36.  
  37.  
  38. int    MaxFuseAdr, SigAdr, RowSize, XORSize;
  39.  
  40. extern    long    prog_time, bulk_time;
  41.  
  42. struct    JedecStruct    Jedec2;
  43.  
  44.  
  45. UBYTE    SignatureTxt[] = "Signature: $00 $00 $00 $00 $00 $00 $00 $00  :  XXXXXXXX";
  46. UBYTE    PTTxt[]        = "PT: 0000000000000000000000000000000000000000000000000000000000000000";
  47. UBYTE    ConTxt[]       = "XOR(n): 00000000    SYN: 0    AC0: 0";
  48. UBYTE    AC1Txt[]       = "AC1(n): 00000000";
  49. UBYTE   XOR10Txt[]     = "XOR(n): 0000000000";
  50. UBYTE   SYN10Txt[]     = "SYN(n): 0000000000";
  51.  
  52.  
  53. UBYTE *CmpText1, *CmpText2, *CmpText3, *CmpText4;
  54.  
  55.  
  56.  
  57.  
  58. /*ProgramGAL
  59.   read JEDEC file and program a GAL
  60.   Syntax: ProgramGAL();
  61. */
  62. void ProgramGAL(void)
  63. {
  64.  
  65.   if (MyRequest(GALTYPE_REQ, AppStrings[MSG_GAL_PROG].as_Str)) {
  66.  
  67.     if (MyFileReq(AppStrings[MSG_LOADJED].as_Str, ".jed", YES, LOAD)) {
  68.  
  69.       if (!(GetJedec((UBYTE *)&path[0]))) {
  70.  
  71.         if (GALType != JedecGALType) {        /*überprüfen, ob der einge-*/
  72.       JedecError(25, NO);            /*stellte GAL-Typ zum Jedec-*/
  73.       return;                /*File paßt*/
  74.         }
  75.  
  76.         if (ReadGALParameter(YES))        /*GAL-Parameter holen*/
  77.       return;                /*bei Fehler return*/
  78.  
  79.         if (!ProgJedecToGAL(PROGGAL)) {
  80.  
  81.       if (JedecSecurity)            /*war im Jedec-File das Sec.*/
  82.         SetSecurity(NO);            /*gesetzt? */ 
  83.  
  84.       MyRequest(INFO_REQ, AppStrings[MSG_GALPROGED].as_Str);
  85.         }
  86.         else
  87.       return;
  88.       }
  89.     }
  90.   }
  91. }
  92.  
  93.  
  94.  
  95. /* GAL kopieren
  96. */
  97. void CopyGAL(void)
  98. {
  99. int    flag;
  100.  
  101.  if (MyRequest(GALTYPE_REQ, AppStrings[MSG_COPY_GAL].as_Str)) {
  102.  
  103.    if (ReadGALParameter(YES))            /*GAL-Parameter holen*/
  104.      return;                    /*bei Fehler return*/
  105.  
  106.    PrintText(AppStrings[MSG_READING_GAL].as_Str, 1);
  107.  
  108.    ReadGALToJedec();
  109.  
  110.    PrintText(AppStrings[MSG_LOWER_OK].as_Str, 0);
  111.  
  112.  
  113.    flag = 0;
  114.  
  115.    for (;;) {
  116.  
  117.      if (flag)
  118.        if (!MyRequest(CONT_REQ, AppStrings[MSG_COPY_AGAIN].as_Str))
  119.          break;
  120.  
  121.      flag = 1;
  122.  
  123.      MyRequest(INFO_REQ, AppStrings[MSG_INS_DEST_GAL].as_Str);
  124.      if (!ReadGALParameter(YES))        /*GAL-Parameter holen*/
  125.        ProgJedecToGAL(COPYGAL);            /*kein Fehler, dann prog.*/
  126.  
  127.    }
  128.  }
  129. }
  130.  
  131.  
  132.  
  133. /* überprüfe, ob GAL leer ist*/
  134. void Leertest(void)
  135. {
  136. int result;
  137.  
  138.  if (MyRequest(GALTYPE_REQ, AppStrings[MSG_BLANK_TEST].as_Str)) {
  139.    if (ReadGALParameter(YES))            /*GAL-Parameter holen*/
  140.      return;                    /*bei Fehler return*/
  141.  
  142.    PrintText(AppStrings[MSG_EXE_BLANK_TEST].as_Str ,1);
  143.  
  144.    result = CheckGAL();
  145.  
  146.    PrintText(AppStrings[MSG_READY].as_Str, 0);
  147.  
  148.    if (result)
  149.      MyRequest(INFO_REQ, AppStrings[MSG_NOT_BLANK].as_Str);
  150.    else
  151.      MyRequest(INFO_REQ, AppStrings[MSG_BLANK].as_Str);
  152.   }
  153. }
  154.  
  155.  
  156.  
  157.  
  158. /* CheckGAL:   teste ob GAL leer ist
  159.    Vor dem Aufruf von dieser Routine sollten mit ReadGALParameter(YES) die
  160.    GAL-Parameter erfolgreich gelesen worden sein.
  161.    Aufruf:   return=CheckGAL();
  162.    Ergebnis: return = 0 : GAL ist leer
  163.               1 : Logik-Matrix ist nicht leer
  164.               2 : Logik-Matrix ist leer, aber Rest nicht
  165. */
  166. int CheckGAL(void)
  167. {
  168. int    n, row;
  169.  
  170.  
  171.  LED(ON);
  172.  EditMode(VERIFY);                /*GAL in Verify-Mode*/
  173.  
  174.                     /*** Logik-Matrix lesen ***/
  175.  for (row = 0; row <= MaxFuseAdr; row++) {
  176.  
  177.    SetRow(row);                /*Adresse anlegen*/
  178.    STRImpuls(VERIFY_TIME);        /*Bits ins Schieberegister holen*/
  179.  
  180.    for (n = 0; n < RowSize; n++) {    /*seriell auslesen*/
  181.  
  182.      if (!SDOut()) {                /*SDOut-Ausgang lesen*/
  183.        ExitEditMode();
  184.        return(1);
  185.      }
  186.  
  187.      Clock();                    /*nächstes Bit an SDOut holen*/
  188.    }
  189.  }
  190.  
  191.  
  192.  SetRow(SigAdr);             /*** Signatur auslesen ***/
  193.  STRImpuls(VERIFY_TIME);
  194.  
  195.  for (n = 0; n < SIG_SIZE; n++) {
  196.  
  197.     if (!SDOut()) {
  198.       ExitEditMode();
  199.       return(2);
  200.     }
  201.  
  202.     Clock();
  203.   }
  204.  
  205.  
  206.                         /*** ACW holen ***/
  207.  if ((GALType == GAL16V8) || (GALType == GAL20V8)) {
  208.    SetRow(ACW_ADR);                /*ACW adressieren*/
  209.    STRImpuls(VERIFY_TIME);            /*Bits ins Schieberegister*/
  210.  
  211.    for (n = 0; n < ACW_SIZE; n++) {
  212.  
  213.      if (!SDOut()) {
  214.        ExitEditMode();
  215.        return(2);
  216.      }
  217.  
  218.      Clock();
  219.  
  220.    }
  221.  
  222.  }
  223.                     /*** GAL22V10 ***/
  224.  
  225.  if (GALType == GAL22V10) {
  226.    SetARCH(1);                    /*ACW adressieren */
  227.    STRImpuls(VERIFY_TIME);            /*Bits ins Schieberegister*/
  228.    
  229.    for (n = 0; n < 20; n++) {
  230.      if (!SDOut()) {
  231.        ExitEditMode();
  232.        return(2);
  233.      }
  234.      Clock();
  235.    }
  236.  
  237.  }
  238.  
  239.                     /*** GAL20RA10 ***/
  240.  if (GALType == GAL20RA10) {
  241.    SetARCH(1);                    /*ACW adressieren */
  242.    STRImpuls(VERIFY_TIME);            /*Bits ins Schieberegister*/
  243.  
  244.    for (n = 0; n < 10; n++) {
  245.      if (!SDOut()) {
  246.        ExitEditMode();
  247.        return(2);
  248.      }
  249.      Clock();
  250.    }
  251.  
  252.  }
  253.  
  254.  
  255.  ExitEditMode();
  256.  return(0);                    /*GAL ist leer*/
  257. }
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264. /*testen, ob Sicherungsbit gesetzt ist
  265.   Das geht so (hoffe ich zumindest): Die Funktion CheckGAL gibt eine 0
  266.   zurück, wenn das GAL leer ist; eine 1, wenn in der Logik-Matrix eine
  267.   0 vorkommt und eine 2, wenn erst im ACW oder in der Signatur eine 0 vor-
  268.   kommt. Wenn in der Logik-Matrix eine 0 vorkommt, kann das Security-Bit
  269.   nicht gesetzt sein. Wenn in der Logik-Matrix nur 1 vorkommt und der Rest
  270.   (Signatur...), der ja auch bei gesetztem Bit ausgelesen werden kann,
  271.   eine 0 enthält, folgt daraus, daß das Secruity-Bit gesetzt ist.
  272. */
  273. void TestSecurity(void)
  274. {
  275. int result;
  276.  
  277.  if (MyRequest(GALTYPE_REQ, AppStrings[MSG_SEC_TEST].as_Str)) {
  278.  
  279.    if (ReadGALParameter(YES))            /*GAL-Parameter holen*/
  280.      return;                    /*bei Fehler return*/
  281.  
  282.    result = CheckGAL();
  283.  
  284.    if (result == 2)
  285.      MyRequest(INFO_REQ, AppStrings[MSG_SEC_SET].as_Str);
  286.    else
  287.      if (result == 1)
  288.        MyRequest(INFO_REQ, AppStrings[MSG_SEC_NOT_SET].as_Str);
  289.      else
  290.        MyRequest(INFO_REQ, AppStrings[MSG_BLANK].as_Str);
  291.   }
  292. }
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300. /* Compare:  führt Vergleich durch zwischen GAL-GAL, GAL-Jedec, Jedec-GAL
  301.    Aufruf:     Compare();
  302.    Ergebnis:     ---
  303. */
  304. void Compare(void)
  305. {
  306. int    n, row, cmptype, execute;
  307. int    logic, acw, signature;
  308. UBYTE    *text;
  309.  
  310.  
  311.  if (!(cmptype = (int)rtEZRequestTags(AppStrings[MSG_CMPTYPE].as_Str,
  312.                 AppStrings[MSG_CMPS].as_Str, NULL, NULL,
  313.                 RT_ReqPos, REQPOS_CENTERSCR, TAG_END)))
  314.    return;                    /* Abbruch => zurück */
  315.  
  316.  
  317.  if (cmptype == 1)                    /*GAL mit GAL*/
  318.    if (!MyRequest(GALTYPE_REQ, AppStrings[MSG_CMP_GALGAL].as_Str))
  319.      return;
  320.  
  321.  if (cmptype == 2)                    /*GAL mit Jedec*/
  322.    if (!MyRequest(GALTYPE_REQ, AppStrings[MSG_CMP_GALJED].as_Str))
  323.      return;
  324.  
  325.  if ((cmptype == 3) && (Config.GALTypeReq))        /*Jedec mit GAL*/
  326.    if (!MyRequest(GALTYPE_REQ, AppStrings[MSG_CMP_JEDGAL].as_Str))
  327.      return;
  328.  
  329.  
  330.  
  331.  if ((cmptype == 1) || (cmptype == 2)) {
  332.  
  333.    if (ReadGALParameter(YES))            /*GAL-Parameter holen*/
  334.      return;                    /*bei Fehler return*/
  335.  
  336.    PrintText(AppStrings[MSG_READING_GAL].as_Str ,1);
  337.  
  338.    ReadGALToJedec();                /*Jedec-Struktur erstellen*/
  339.  
  340.    PrintText(AppStrings[MSG_LOWER_OK].as_Str ,0);
  341.  }
  342.  
  343.  if (cmptype == 3) {
  344.  
  345.    if (MyFileReq(AppStrings[MSG_LOADJED].as_Str, ".jed", YES, LOAD)) {
  346.  
  347.      if (GetJedec((UBYTE *)&path[0]))        /*Jedec-File in Struktur*/
  348.        return;
  349.  
  350.      if (GALType != JedecGALType) {        /*überprüfen, ob der einge-*/
  351.        JedecError(25,NO);            /*stellte GAL-Typ zum Jedec-*/
  352.        return;                    /*File paßt*/
  353.      }
  354.  
  355.    }
  356.    else
  357.      return;
  358.  }
  359.  
  360.  
  361.  for (n = 0; n < sizeof(Jedec2); n++)        /*Jedec-Struktur sichern*/
  362.    Jedec2.GALLogic[n] = Jedec.GALLogic[n];
  363.  
  364.  
  365.  for (;;) {
  366.  
  367.    execute = 1;
  368.  
  369.    if ((cmptype == 1) || (cmptype == 3)) {
  370.  
  371.      MyRequest(INFO_REQ, AppStrings[MSG_GAL_TO_CMP].as_Str);
  372.  
  373.      if (!ReadGALParameter(YES)) {        /*GAL-Parameter holen*/
  374.        PrintText(AppStrings[MSG_READING_GAL].as_Str, 1);    /*o.k.? dann weiter*/
  375.  
  376.        ReadGALToJedec();
  377.  
  378.        PrintText(AppStrings[MSG_LOWER_OK].as_Str, 0);
  379.      }
  380.      else
  381.        execute = 0;
  382.    }
  383.  
  384.  
  385.    if (cmptype == 2) {
  386.  
  387.      if (MyFileReq(AppStrings[MSG_LOADJED].as_Str, ".jed", YES, LOAD)) {
  388.  
  389.        if (GetJedec((UBYTE *)&path[0]))        /*Jedec-File in Struktur*/
  390.      execute = 0;
  391.  
  392.        if (GALType != JedecGALType) {        /*überprüfen, ob der einge-*/
  393.      JedecError(25,NO);            /*stellte GAL-Typ zum Jedec-*/
  394.      execute = 0;
  395.        }
  396.  
  397.      }
  398.      else
  399.        execute = 0;
  400.    }
  401.  
  402.  
  403.    if (execute) {            /*** Compare ausführen ***/
  404.      logic = acw = signature = 1;
  405.  
  406.                         /*Logik-Matrizen vergleichen*/
  407.      for (row = 0; row <= MaxFuseAdr; row++) {
  408.  
  409.        for (n = 0; n < RowSize; n++) {
  410.  
  411.          if (Jedec.GALLogic[row+(MaxFuseAdr+1)*n] != Jedec2.GALLogic[row+(MaxFuseAdr+1)*n]) {
  412.        logic = 0;
  413.          }
  414.  
  415.          if (!logic) break;
  416.        }
  417.  
  418.        if (!logic) break;
  419.      }
  420.  
  421.                         /* Signatur vergleichen */
  422.      for (n = 0; n < SIG_SIZE; n++) {
  423.        if (Jedec.GALSig[n] != Jedec2.GALSig[n])
  424.      signature = 0;
  425.      }
  426.  
  427.                         /* ACW vergleichen */
  428.      if ((GALType == GAL16V8) || (GALType == GAL20V8)) {
  429.  
  430.        if (Jedec.GALSYN != Jedec2.GALSYN)
  431.      acw = 0;
  432.  
  433.        if (Jedec.GALAC0 != Jedec2.GALAC0)
  434.      acw = 0;
  435.  
  436.        for (n = 0; n < 8; n++)
  437.      if (Jedec.GALXOR[n] != Jedec2.GALXOR[n])
  438.        acw = 0;
  439.  
  440.        for (n = 0; n < 8; n++)
  441.      if (Jedec.GALAC1[n] != Jedec2.GALAC1[n])
  442.        acw = 0;
  443.  
  444.        for (n = 0; n < PT_SIZE; n++)
  445.      if (Jedec.GALPT[n] != Jedec2.GALPT[n])
  446.        acw = 0;
  447.  
  448.      }
  449.      else {
  450.  
  451.        for (n = 0; n < 10; n++)
  452.      if (Jedec.GALXOR[n] != Jedec2.GALXOR[n])
  453.        acw = 0;
  454.  
  455.        if (GALType == GAL22V10)
  456.      for (n = 0; n < 10; n++)
  457.        if (Jedec.GALS1[n] != Jedec2.GALS1[n])
  458.          acw = 0;
  459.  
  460.      }
  461.  
  462.                 /*** Ergebnis des Vergleichs ausgeben ***/
  463.  
  464.      if (logic && acw && signature)        /*völlig identisch?*/
  465.        text = CmpText1;
  466.  
  467.      if (!logic || !acw)            /*NICHT identisch?*/
  468.        text = CmpText2;
  469.  
  470.      if (logic && acw && !signature)        /*bis auf Sig. identisch?*/
  471.        text = CmpText3;
  472.    }
  473.    else
  474.      text = CmpText4;                /*Vergleich abgebrochen*/
  475.  
  476.  
  477.    if (!MyRequest(CONT_REQ, text))
  478.      return;                    
  479.  
  480.  }
  481. }
  482.  
  483.  
  484.  
  485.  
  486. /****************************************************************/
  487. /* Die nachfolgenden Routinen greifen direkt über das Modul    */
  488. /* "port.asm" auf das GAL zu.                    */
  489. /****************************************************************/
  490.  
  491. /* PrintACW
  492.    gibt das Architecture Control Word aus
  493.    Aufruf: PrintACW
  494. */
  495. void PrintACW(void)
  496. {
  497. BYTE    bit;
  498. int    n, acw_num, xor_num, ac1_num ;
  499.  
  500.  acw_num = xor_num = ac1_num =0;
  501.  
  502.  if (MyRequest(GALTYPE_REQ, AppStrings[MSG_READ_ACW].as_Str)) {
  503.  
  504.    if (ReadGALParameter(YES))            /*GAL-Parameter holen*/
  505.      return;                    /*bei Fehler return*/
  506.  
  507.    LED(ON);                    /*LED anschalten*/
  508.    EditMode(VERIFY);                /*GAL in Edit-Mode versetzen*/
  509.  
  510.                     /*** 16V8, 20V8 ***/
  511.    if ((GALType == GAL16V8) || (GALType == GAL20V8)) {
  512.  
  513.      SetRow(ACW_ADR);                /*ACW adressieren*/
  514.      STRImpuls(VERIFY_TIME);            /*ACW ins Schiebereg. holen*/
  515.  
  516.      for (n = 0; n < ACW_SIZE; n++) {        /*ACW einlesen*/
  517.  
  518.        bit = (BYTE)SDOut();
  519.        Clock();
  520.  
  521.                     /*Standard-Typ (kein A-Typ)*/
  522.        if (!GALAType()) {
  523.  
  524.      if (n < 32) {                /*PT0-31 eintragen*/
  525.            PTTxt[4+acw_num]=bit+'0';
  526.        acw_num++;
  527.      }
  528.  
  529.       if (n >= 50) {                /*PT32-63 eintragen*/
  530.            PTTxt[4+acw_num]=bit+'0';
  531.        acw_num++;
  532.      }
  533.  
  534.      if (n == 36)                 /*AC0-Bit*/
  535.        ConTxt[35]=bit+'0';
  536.  
  537.      if (n == 45)                 /*SYN-Bit*/
  538.        ConTxt[25]=bit+'0';
  539.  
  540.      if ((n >= 32) && (n <= 35)) {         /*4 XOR-Bits*/
  541.        ConTxt[8+xor_num]=bit+'0';
  542.        xor_num++;
  543.      }
  544.  
  545.      if ((n >= 46) && (n <= 49)) {         /*4 XOR-Bits*/
  546.        ConTxt[8+xor_num]=bit+'0';
  547.        xor_num++;
  548.      }
  549.  
  550.      if ((n >= 37) && (n <= 44)) {        /*AC1-Bits*/
  551.        AC1Txt[8+ac1_num]=bit+'0';
  552.        ac1_num++;
  553.      }
  554.  
  555.        }
  556.        else {                /*A-Typ*/
  557.  
  558.      if ((n >= 9) && (n <= 72)) {        /*PT0-63 eintragen*/
  559.            PTTxt[4+acw_num]=bit+'0';
  560.        acw_num++;
  561.      }
  562.  
  563.      if (n == 36)                 /*AC0-Bit*/
  564.        ConTxt[35]=bit+'0';
  565.  
  566.      if (n == 77)                 /*SYN-Bit*/
  567.        ConTxt[25]=bit+'0';
  568.  
  569.      if (n <= 3) {                 /*XOR-Bits*/
  570.        ConTxt[8+xor_num]=bit+'0';
  571.        xor_num++;
  572.      }
  573.  
  574.      if (n >= 78) {                 /*XOR-Bits*/
  575.        ConTxt[8+xor_num]=bit+'0';
  576.        xor_num++;
  577.      }
  578.  
  579.      if ((n >= 5) && (n <= 8)) {        /*AC1-Bits*/
  580.        AC1Txt[8+ac1_num]=bit+'0';
  581.        ac1_num++;
  582.      }
  583.  
  584.      if ((n >= 73) && (n <= 76)) {        /*AC1-Bits*/
  585.        AC1Txt[8+ac1_num]=bit+'0';
  586.        ac1_num++;
  587.          }
  588.        }
  589.      }
  590.  
  591.      PrintText((UBYTE *)&PTTxt[0], 1);
  592.      PrintText((UBYTE *)&ConTxt[0], 1);
  593.      PrintText((UBYTE *)&AC1Txt[0], 1);
  594.    }
  595.  
  596.  
  597.                 /*** GAL22V10 ***/
  598.    if (GALType == GAL22V10) {
  599.      SetARCH(1);            /*Architecture-Control-Word */
  600.      STRImpuls(VERIFY_TIME);        /*ACW ins Schiebereg. holen*/
  601.  
  602.      for (n = 0; n < 10; n++) {
  603.        SYN10Txt[8 + n] = SDOut() + '0';        /* S1 holen */
  604.        Clock();
  605.  
  606.        XOR10Txt[8 + n] = SDOut() + '0';        /* XORs holen */
  607.        Clock();
  608.      }
  609.  
  610.      PrintText((UBYTE *)&XOR10Txt[0], 1);
  611.      PrintText((UBYTE *)&SYN10Txt[0], 1);
  612.    }
  613.  
  614.  
  615.                 /*** GAL20RA10 ***/
  616.    if (GALType == GAL20RA10) {
  617.      SetARCH(1);            /*Architecture-Control-Word */
  618.      STRImpuls(VERIFY_TIME);        /*ACW ins Schiebereg. holen*/
  619.  
  620.      for (n = 0; n < 10; n++) {
  621.        XOR10Txt[8 + n] = SDOut() + '0';        /* XORs holen */
  622.        Clock();
  623.      }
  624.  
  625.      PrintText((UBYTE *)&XOR10Txt[0], 1);
  626.    }
  627.  
  628.  
  629.    ExitEditMode();
  630.  
  631.   }
  632. }
  633.  
  634.  
  635.  
  636. /* PrintSignature
  637.    gibt Signatur im Textfeld aus
  638.    Aufruf: PrintSignature();
  639. */
  640. void PrintSignature(void)
  641. {
  642. UBYTE    strn[6];
  643. BYTE    byte;
  644. int    n;
  645.  
  646.  if (MyRequest(GALTYPE_REQ, AppStrings[MSG_READ_SIG].as_Str)) {
  647.  
  648.    if (ReadGALParameter(YES))            /*GAL-Parameter holen*/
  649.      return;                    /*bei Fehler return*/
  650.  
  651.    LED(ON);                    /*LED anschalten*/
  652.  
  653.    EditMode(VERIFY);                /*GAL in Edit-Mode versetzen*/
  654.  
  655.    SetRow(SigAdr);                /*Signatur adressieren*/
  656.  
  657.    STRImpuls(VERIFY_TIME);            /*Signatur ins Schiebereg. holen*/
  658.                     /*** Signatur einlesen ***/
  659.    byte = 0;
  660.    for (n = 0; n < SIG_SIZE; n++) {
  661.  
  662.      byte |= (BYTE)SDOut();            /*acht Bits zu einem Byte*/
  663.  
  664.      if (!((n+1)%8)) {                /*Text erstellen*/
  665.  
  666.        sprintf((char *)&strn[0], "%02x", (UWORD)byte);
  667.  
  668.        strncpy((char *)&SignatureTxt[12+4*((n+1)/8-1)], (char *)&strn[0], (size_t)2);
  669.  
  670.        if (isprint(byte))
  671.          SignatureTxt[47+((n+1)/8-1)] = byte;
  672.        else
  673.          SignatureTxt[47+((n+1)/8-1)] = '.';
  674.  
  675.        byte = 0;
  676.      }
  677.  
  678.      byte <<= 1;
  679.  
  680.      Clock();
  681.    } 
  682.    ExitEditMode();
  683.  
  684.    PrintText((UBYTE *)&SignatureTxt[0], 1);
  685.  }
  686. }
  687.  
  688.  
  689.  
  690.  
  691. /* ProgJedecToGAL
  692.    schreibt die Jedec-Struktur in das GAL
  693.    (eigentliche Programmier-Routine)
  694.    Aufruf:    result = ProgJedecToGAL(mode);
  695.    Parameter: mode = COPYGAL: Aufruf erfolgt von GAL-Copy-Routine
  696.            = PROGGAL: Aufruf erfolgt von GAL-Programmier-Routine
  697.  
  698.    Ergebnis: 0: GAL erfolgreich programmiert
  699.          1: GAL wurde nicht programmiert, da es nicht leer ist
  700.          2: Verify ist fehlgeschlagen
  701. */
  702. int ProgJedecToGAL(int mode)
  703. {
  704. int    n, i, row, bit;
  705.  
  706.                     /*Leertest durchführen*/
  707.   if (((mode == COPYGAL) && Config.CopyEmptyTest) || ((mode == PROGGAL) && Config.ProgEmptyTest)) {
  708.  
  709.     PrintText(AppStrings[MSG_EXE_BLANK_TEST].as_Str, 1);
  710.  
  711.     if (CheckGAL()) {
  712.       PrintText(AppStrings[MSG_NOT_BLANK2].as_Str, 0);
  713.  
  714.       if (MyRequest(ERASE_REQ, AppStrings[MSG_NOT_BLNK_ERS].as_Str))
  715.         EraseIt();
  716.       else
  717.         return(1);
  718.     }
  719.     else
  720.       PrintText(AppStrings[MSG_LOWER_OK].as_Str, 0);
  721.  
  722.   }
  723.  
  724.  
  725.   PrintText(AppStrings[MSG_PROGING_GAL].as_Str, 1);
  726.  
  727.  
  728.  
  729.   LED(ON);
  730.   EditMode(PROG);
  731.                 /*** GAL16V8, GAL20V8 **/
  732.          
  733.   if ((GALType == GAL16V8) || (GALType == GAL20V8)) {
  734.  
  735.                 /*** Logik-Matrix schreiben ***/
  736.     for (row = 0; row <= MaxFuseAdr; row++) {
  737.       SetRow(row);
  738.  
  739.       for (n = 0; n < RowSize; n++) {
  740.         SDIn((int)Jedec.GALLogic[row+(MaxFuseAdr+1)*n]); /*Bit an SDIn-Eingang anlegen*/
  741.         Clock();            /*Bit in Schieberegister takten*/
  742.       }
  743.  
  744.       SetPV(PROG);            /*P/V auf "programmieren"*/
  745.       STRImpuls(prog_time);        /*Row (64 Bit) programmieren*/
  746.       SetPV(VERIFY);            /*P/V wieder auf "lesen"*/
  747.     }
  748.  
  749.  
  750.  
  751.     SetRow(SigAdr);        /*** Signatur schreiben ***/
  752.  
  753.     for (n = 0; n < SIG_SIZE; n++) {
  754.       SDIn((int)Jedec.GALSig[n]);    /*Bit an SDIn-Eingang anlegen*/
  755.       Clock();                /*Bit in Schieberegister takten*/
  756.     }
  757.  
  758.     SetPV(PROG);                /*P/V auf "programmieren"*/
  759.     STRImpuls(prog_time);            /*Daten programmieren*/
  760.     SetPV(VERIFY);                /*P/V auf "lesen"*/
  761.  
  762.  
  763.  
  764.     SetRow(ACW_ADR);        /*** ACW schreiben ***/
  765.  
  766.     for (n = 0; n < ACW_SIZE; n++) {
  767.  
  768.       if (!GALAType()) {        /*** Standard-Typ (kein A-Typ) ***/
  769.  
  770.     if (n <= 31)                /*PT0-PT31*/
  771.       bit = Jedec.GALPT[n];
  772.  
  773.     if ((n >= 32) && (n <= 35))        /*4 XOR-Bits*/
  774.       bit = Jedec.GALXOR[n-32];
  775.  
  776.     if (n == 36)                /*AC0-Bit*/
  777.       bit = Jedec.GALAC0;
  778.  
  779.     if ((n >= 37) && (n <= 44))         /*AC1-Bits*/
  780.       bit = Jedec.GALAC1[n-37];
  781.  
  782.     if (n == 45)                 /*SYN-Bit*/
  783.       bit = Jedec.GALSYN;
  784.  
  785.     if ((n >= 46) && (n <= 49))        /*4 XOR-Bits*/
  786.       bit = Jedec.GALXOR[n-42];
  787.  
  788.     if ((n >= 50) && (n <= 81))        /*PT32-PT63*/
  789.       bit = Jedec.GALPT[n-18];
  790.  
  791.       }
  792.       else {                /*** A-Typ ***/
  793.  
  794.     if (n <= 3)                /*4 XOR-Bits*/
  795.       bit = Jedec.GALXOR[n];
  796.  
  797.     if (n == 4)                /*AC0-Bit*/
  798.       bit = Jedec.GALAC0;
  799.  
  800.     if ((n >= 5) && (n <= 8))            /*AC1-Bits*/
  801.       bit = Jedec.GALAC1[n-5];
  802.  
  803.     if ((n >= 9) && (n <= 72))        /*PT0-PT63*/
  804.       bit = Jedec.GALPT[n-9];
  805.  
  806.     if ((n >= 73) && (n <= 76))        /*AC1-Bits*/
  807.       bit = Jedec.GALAC1[n-69];
  808.  
  809.     if (n == 77)                /*SYN-Bit*/
  810.       bit = Jedec.GALSYN;
  811.  
  812.     if (n >= 78)                /*XOR-Bits*/
  813.       bit = Jedec.GALXOR[n-74];
  814.  
  815.       }
  816.  
  817.       SDIn((int)bit);            /*Bit an SDIn-Eingang anlegen*/
  818.       Clock();                /*Bit in Schieberegister takten*/
  819.     }
  820.  
  821.     SetPV(PROG);                /*P/V auf "programmieren"*/
  822.     STRImpuls(prog_time);            /*Daten programmieren*/
  823.     SetPV(VERIFY);            /*P/V auf "lesen"*/
  824.  
  825.   }
  826.   else {            /*** GAL20RA10, GAL22V10 ***/
  827.                 /*** Logik-Matrix schreiben ***/
  828.     for (row = 0; row <= MaxFuseAdr; row++) {
  829.  
  830.       for (n = 0; n < RowSize; n++) {
  831.         SDIn((int)Jedec.GALLogic[row+(MaxFuseAdr+1)*n]); /*Bit an SDIn-Eingang anlegen*/
  832.         Clock();            /*Bit in Schieberegister takten*/
  833.       }
  834.  
  835.       SetRow(row);
  836.       SDIn(0);
  837.       SetPV(PROG);            /*P/V auf "programmieren"*/
  838.       STRImpuls(prog_time);        /*Row (64 Bit) programmieren*/
  839.       SetPV(VERIFY);            /*P/V wieder auf "lesen"*/
  840.     }
  841.  
  842.                 /*** Signatur schreiben ***/
  843.     for (n = 0; n < SIG_SIZE; n++) {
  844.       SDIn((int)Jedec.GALSig[n]);    /*Bit an SDIn-Eingang anlegen*/
  845.       Clock();                /*Bit in Schieberegister takten*/
  846.     }
  847.  
  848.     for (n = 0; n < 132-SIG_SIZE; n++) { /*fehlende Bits reintakten*/
  849.       SDIn(1);
  850.       Clock();
  851.     }
  852.  
  853.     SetRow(SigAdr);
  854.     SDIn(0);
  855.     SetPV(PROG);                /*P/V auf "programmieren"*/
  856.     STRImpuls(prog_time);            /*Daten programmieren*/
  857.     SetPV(VERIFY);                /*P/V auf "lesen"*/
  858.  
  859.  
  860.  
  861.                 /*** ACW schreiben ***/
  862.     SetARCH(1);                    /* Architecture-Array */
  863.     for (n = 0; n < 10; n++) {
  864.       if (GALType == GAL22V10) {        /* bei 22V10 SYN zuerst */
  865.     SDIn((int)Jedec.GALS1[n]);
  866.     Clock();
  867.       }
  868.  
  869.       SDIn((int)Jedec.GALXOR[n]);        /* XOR eintakten */
  870.       Clock();
  871.     }
  872.  
  873.     SDIn(0);
  874.     SetPV(PROG);                /*P/V auf "programmieren"*/
  875.     STRImpuls(prog_time);            /*Daten programmieren*/
  876.     SetPV(VERIFY);                /*P/V auf "lesen"*/
  877.  
  878.   }
  879.  
  880.   ExitEditMode();
  881.  
  882.  
  883.   PrintText(AppStrings[MSG_LOWER_OK].as_Str, 0);
  884.  
  885.  
  886.  
  887.                 /*** Verify durchführen ***/
  888.  
  889.   if (((mode == COPYGAL) && Config.CopyVerify) || ((mode == PROGGAL) && Config.ProgVerify)) {
  890.  
  891.     PrintText(AppStrings[MSG_VERIFYING].as_Str, 1);
  892.  
  893.     for (n = 0; n < sizeof(Jedec2); n++)    /*Jedec-Struktur sichern*/
  894.       Jedec2.GALLogic[n] = Jedec.GALLogic[n];
  895.  
  896.     ReadGALToJedec();            /*GAL nach Programmierung einlesen*/
  897.  
  898.     for (i = 0; i < sizeof(Jedec); i++) {    /*Jedec-Strukturen vergleichen*/
  899.       if (Jedec.GALLogic[i] != Jedec2.GALLogic[i]) {
  900.         MyRequest(ERR_REQ, AppStrings[MSG_VERFAILED].as_Str);
  901.  
  902.         PrintText(AppStrings[MSG_FAILED].as_Str, 0);
  903.  
  904.     for (i = 0; i < sizeof(Jedec2); i++)    /*Jedec-Struktur restaurieren*/
  905.       Jedec.GALLogic[i] = Jedec2.GALLogic[i];
  906.  
  907.     return(2);
  908.       }
  909.     }
  910.  
  911.     for (n = 0; n < sizeof(Jedec2); n++)    /*Jedec-Struktur restaurieren*/
  912.       Jedec.GALLogic[n] = Jedec2.GALLogic[n];    /*wurde durch Verify überschrieben*/
  913.  
  914.     PrintText(AppStrings[MSG_LOWER_OK].as_Str, 0);
  915.   }
  916.  
  917.   return(0);
  918. }
  919.  
  920.  
  921.  
  922.  
  923.  
  924. /* ReadGALToJedec
  925.    liest das GAL in die Jedec-Struktur
  926.    (MaxFuseAdr, SigAdr, RowSize müssen initialisiert sein)
  927.    Aufruf:  ReadGALToJedec()
  928. */
  929. void ReadGALToJedec(void)
  930. {
  931. int    n, row;
  932. BYTE    bit;
  933.  
  934.  
  935.   LED(ON);
  936.   EditMode(VERIFY);                /*GAL in Verify-Mode*/
  937.  
  938.                     /*** Logik-Matrix lesen ***/
  939.   for (row = 0; row <= MaxFuseAdr; row++) {
  940.     SetRow(row);                /*Adresse anlegen*/
  941.  
  942.     STRImpuls(VERIFY_TIME);            /*Bits ins Schieberegister holen*/
  943.  
  944.     for (n = 0; n < RowSize; n++) {        /*seriell auslesen*/
  945.       Jedec.GALLogic[row+(MaxFuseAdr+1)*n] = (BYTE)SDOut();
  946.       Clock();                    /*nächstes Bit an SDOut holen*/
  947.     }
  948.   }
  949.  
  950.  
  951.  
  952.   SetRow(SigAdr);             /*** Signatur auslesen ***/
  953.   STRImpuls(VERIFY_TIME);
  954.  
  955.   for (n = 0; n < SIG_SIZE; n++) {
  956.     Jedec.GALSig[n] = (BYTE)SDOut();
  957.     Clock();
  958.   }
  959.  
  960.                 /*** Architecture Control Word (ACW) holen ***/
  961.  
  962.   if ((GALType == GAL16V8) || (GALType == GAL20V8)) {
  963.  
  964.     SetRow(ACW_ADR);
  965.     STRImpuls(VERIFY_TIME);            /*Bits ins Schieberegister*/
  966.  
  967.     for (n = 0; n < ACW_SIZE; n++) {
  968.  
  969.       bit = (BYTE)SDOut();
  970.       Clock();
  971.  
  972.       if (!GALAType()) {           /*** kein A-Typ ***/
  973.  
  974.     if (n <= 31)
  975.       Jedec.GALPT[n] = bit;
  976.  
  977.     if ((n >= 32) && (n <= 35))        /*4 XOR-Bits*/
  978.       Jedec.GALXOR[n-32] = bit;
  979.  
  980.     if (n == 36)                /*AC0-Bit*/
  981.       Jedec.GALAC0 = bit;
  982.  
  983.     if ((n >= 37) && (n <= 44))        /*AC1-Bits*/
  984.       Jedec.GALAC1[n-37] = bit;
  985.  
  986.     if (n == 45)                 /*SYN-Bit*/
  987.       Jedec.GALSYN=bit;
  988.  
  989.     if ((n >= 46) && (n <= 49))        /*4 XOR-Bits*/
  990.       Jedec.GALXOR[n-42] = bit;
  991.  
  992.     if ((n >= 50) && (n <= 81))        /*PT32-PT63*/
  993.       Jedec.GALPT[n-18] = bit;
  994.  
  995.       }
  996.       else {                /*** A-Typ ***/
  997.  
  998.     if (n <= 3)                /*4 XOR-Bits 19-16*/
  999.       Jedec.GALXOR[n] = bit;
  1000.  
  1001.     if (n == 4)                /*AC0-Bit*/
  1002.       Jedec.GALAC0 = bit;
  1003.  
  1004.     if ((n >= 5) && (n <= 8))        /*AC1-Bits*/
  1005.       Jedec.GALAC1[n-5] = bit;
  1006.  
  1007.     if ((n >= 9) && (n <= 72))        /*PT0-PT63*/
  1008.       Jedec.GALPT[n-9] = bit;
  1009.  
  1010.     if (n == 77)                /*SYN-Bit*/
  1011.       Jedec.GALSYN = bit;
  1012.  
  1013.     if ((n >= 73) && (n <= 76))        /*AC1-Bits*/
  1014.       Jedec.GALAC1[n-69] = bit;
  1015.  
  1016.     if (n >= 78)                /*XOR-Bits*/
  1017.       Jedec.GALXOR[n-74] = bit;
  1018.       }
  1019.     }
  1020.  
  1021.   }
  1022.  
  1023.                     /*** 22V10 ***/
  1024.   if (GALType == GAL22V10) {
  1025.     SetARCH(1);                    /* Architecture-Word lesen*/
  1026.     STRImpuls(VERIFY_TIME);            /* Bits ins Schieberegister*/
  1027.  
  1028.     for (n = 0; n < 10; n++) {
  1029.       Jedec.GALS1[n] = (BYTE)SDOut();        /* S1x holen */
  1030.       Clock();
  1031.  
  1032.       Jedec.GALXOR[n]  = (BYTE)SDOut();        /* XORx holen */
  1033.       Clock();
  1034.     }
  1035.   }
  1036.  
  1037.                     /*** 20RA10 ***/
  1038.   if (GALType == GAL20RA10) {
  1039.     SetARCH(1);                    /* Architecture-Word lesen */
  1040.     STRImpuls(VERIFY_TIME);            /* Bits ins Schieberegister*/
  1041.  
  1042.     for (n = 0; n < 10; n++) {
  1043.       Jedec.GALXOR[n] = (BYTE)SDOut();            /* XORx holen */
  1044.       Clock();
  1045.     }
  1046.   }
  1047.  
  1048.  
  1049.   ExitEditMode();
  1050. }
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056. /* Sicherungsbit setzen
  1057.     flag = 0: Aufruf von der ProgramGAL-Routine aufgrund eines
  1058.           gesetzten "JedecSecurity"-Flags
  1059.     flag = 1: Aufruf von einer anderen Routine als der ProgramGAL-Routine
  1060. */
  1061. void SetSecurity(int flag)
  1062. {
  1063. int result;
  1064.  
  1065.   if (flag)
  1066.     result = MyRequest(GALTYPE_REQ, AppStrings[MSG_SET_SEC].as_Str);
  1067.   else
  1068.     result = MyRequest(CONT_REQ, AppStrings[MSG_SET_SEC].as_Str);
  1069.  
  1070.   if (result) {
  1071.  
  1072.     if (flag)
  1073.       if (ReadGALParameter(YES))        /*GAL-Parameter holen*/
  1074.         return;                    /*bei Fehler return*/
  1075.  
  1076.     LED(ON);
  1077.  
  1078.     EditMode(PROG);
  1079.  
  1080.     SetRow(SECURITY_ADR);
  1081.  
  1082.     SetPV(PROG);                /*P/V-Pin auf "programmieren*/
  1083.  
  1084.     STRImpuls(prog_time);            /*STR-Impuls geben*/
  1085.  
  1086.     SetPV(VERIFY);                /*P/V wieder auf "lesen*/
  1087.  
  1088.     ExitEditMode();
  1089.  
  1090.     if (flag)
  1091.       MyRequest(INFO_REQ, AppStrings[MSG_SEC_IS_SET].as_Str);
  1092.   }
  1093. }
  1094.  
  1095.  
  1096.  
  1097.  
  1098.  
  1099. /* GAL löschen */
  1100. void Loeschen(void)
  1101. {
  1102. int result;
  1103.  
  1104.   if (MyRequest(GALTYPE_REQ, AppStrings[MSG_ERASE_GAL].as_Str)){
  1105.     if (ReadGALParameter(YES))            /*GAL-Parameter holen*/
  1106.       return;                    /*bei Fehler return*/
  1107.  
  1108.     EraseIt();
  1109.  
  1110.     if (Config.EraseEmptyTest) {
  1111.       PrintText(AppStrings[MSG_GAL_ERASED].as_Str, 1);
  1112.  
  1113.       PrintText(AppStrings[MSG_EXE_BLANK_TEST].as_Str, 1);
  1114.  
  1115.       result = CheckGAL();
  1116.  
  1117.       PrintText(AppStrings[MSG_READY].as_Str, 0);
  1118.  
  1119.       if (result) {
  1120.         MyRequest(ERR_REQ, AppStrings[MSG_ERASE_FAILED].as_Str);
  1121.         return;
  1122.       }
  1123.     }
  1124.  
  1125.     MyRequest(INFO_REQ, AppStrings[MSG_ERASED].as_Str);
  1126.   }
  1127. }
  1128.  
  1129.  
  1130.  
  1131. /*GAL löschen.
  1132.   Vor dem Aufruf sollten die GAL-Parameter eingelesen worden sein (mit
  1133.   ReadGALParameter(YES);)
  1134. */
  1135. void EraseIt(void)
  1136. {
  1137.  
  1138.    LED(ON);
  1139.  
  1140.    EditMode(PROG);
  1141.  
  1142.  
  1143.    if ((GALType == GAL16V8) || (GALType == GAL20V8)) {
  1144.      SetRow(ERASE_ADR);
  1145.      SDIn(1);
  1146.      SetPV(PROG);            /*P/V-Pin auf "programmieren"*/
  1147.      STRImpuls(bulk_time);        /*STR-Imputs geben*/
  1148.      SetPV(VERIFY);            /*und P/V wieder auf "lesen"*/
  1149.    }
  1150.  
  1151.  
  1152.    if (GALType == GAL22V10) {
  1153.      SDIn(1);
  1154.      SetPV(PROG);
  1155.      SetANDBE(1);
  1156.      SetARCH(1);
  1157.      SetBE(1);
  1158.      SetCLR(1);
  1159.      SetERASE(1);
  1160.  
  1161.      STRImpuls(bulk_time);
  1162.  
  1163.      SetPV(VERIFY);
  1164.      SetANDBE(0);
  1165.      SetARCH(0);
  1166.      SetBE(0);
  1167.      SetCLR(0);
  1168.      SetERASE(0);
  1169.    }
  1170.  
  1171.  
  1172.    if (GALType == GAL20RA10) {
  1173.      SDIn(1);
  1174.      SetPV(PROG);
  1175.      SetPESSAVE(1);
  1176.      SetARCH(1);
  1177.      SetBE(1);
  1178.      SetCLR(1);
  1179.  
  1180.      STRImpuls(bulk_time);        /* Architecture-Array löschen */
  1181.  
  1182.      SetARCH(0);
  1183.  
  1184.      STRImpuls(bulk_time);        /* AND-Array löschen */
  1185.  
  1186.      SetPV(VERIFY);
  1187.      SetPESSAVE(0);
  1188.      SetBE(0);
  1189.      SetCLR(0);
  1190.    }
  1191.  
  1192.  
  1193.    ExitEditMode();
  1194.  
  1195. }
  1196.  
  1197.